const visible = {
    /***
     * 模块内部的 action、mutation 和 getter 是注册在全局命名空间
     * 通过添加 namespaced: true 的方式使其成为带命名空间的模块
     */
    namespaced: true,
    /** */
    state: {
        loadingdata: JSON.parse(sessionStorage.getItem('loadingdata')) || false,
        alldropdownvisible: JSON.parse(sessionStorage.getItem('loadingdata')) || true,
        bgWhite: JSON.parse(sessionStorage.getItem('bgWhite')) || false
    },
    /**mutation 必须是同步函数，this.$store.commit('xxx')触发
     * mapMutations 在组件中可使用mapMutations，将 this.xxx() 映射为 this.$store.commit('xxx')
     */
    mutations: {
        set_loadingvisible: (state, loadingdata) => {
            state.loadingdata = loadingdata;
            if (loadingdata == null || loadingdata == undefined) {
                sessionStorage.removeItem("loadingdata");
            } else {
                sessionStorage.setItem("loadingdata", loadingdata);
            }
        },
        set_alldropdownvisible: (state, alldropdownvisible) => {
            state.alldropdownvisible = alldropdownvisible;
            if (alldropdownvisible == null || alldropdownvisible == undefined) {
                sessionStorage.removeItem("alldropdownvisible");
            } else {
                sessionStorage.setItem("alldropdownvisible", alldropdownvisible);
            }
        },
        set_bgWhite: (state, bgWhite) => {
            state.bgWhite = bgWhite;
            if (bgWhite == null || bgWhite == undefined) {
                sessionStorage.removeItem("bgWhite");
            } else {
                sessionStorage.setItem("bgWhite", bgWhite);
            }
        }
    },
    /** actions 可异步, this.$store.dispatch('xxx')触发
     * mapActions 在组件中可使用mapActions，将this.xxx() 映射为this.$store.dispatch('xxx') 
     * */
    actions: {
        cache_loadingvisible({
            commit
        }, loadingdata) {
            commit('set_loadingvisible', loadingdata);
        },
        removeloadingvisible({
            commit
        }) {
            commit('set_loadingvisible', null);
        },
        cache_alldropdownvisible({
            commit
        }, alldropdownvisible) {
            commit('set_alldropdownvisible', alldropdownvisible);
        },
        remove_alldropdownvisible({
            commit
        }) {
            commit('set_alldropdownvisible', null);
        },
        cache_bgWhite({
            commit
        }, bgWhite) {
            commit('set_bgWhite', bgWhite);
        },
        remove_bgWhite({
            commit
        }) {
            commit('set_bgWhite', null);
        },
        removeAll({
            commit
        }) {
            commit('set_loadingvisible', null);
            commit('set_alldropdownvisible', null);
            commit('set_bgWhite', null);
        }
    },
    /**
     * mapGetters 在组件中可使用mapGetters，将this.xxx 映射为 this.$store.getters.xxx
     */
    getters: {
        loadingdata: state => {
            return state.loadingdata
        }
    }
}

export default visible